using System;
using Castle.ActiveRecord;
using CosyTrade.Data;

namespace CosyTrade.StoreManagement
{
    [AddPropertyChangedNotifyInterface, PropertyChangedNotify]
    [Serializable, ActiveRecord("importBillItems")]
    public class ImportBillItem : BusinessObject
    {
        private readonly Guid primaryKey = Guid.NewGuid();
        private ExportBillItem maptoExportBillItem;
        private float price = 0f;
        private int unitCount;
        private int packageCount;
        private int totalCount;

        [PrimaryKey(PrimaryKeyType.Assigned, "ROWGUID", Access=PropertyAccess.NosetterCamelcase)]
        public Guid PrimaryKey
        {
            get { return primaryKey; }
        }
        
        [BelongsTo("maptoExportBillItemGuid")]
        public ExportBillItem MaptoExportBillItem
        {
            get { return maptoExportBillItem; }
            set { maptoExportBillItem = value; }
        }

        public string ShortCode
        {
            get
            {
                if (maptoExportBillItem != null) return maptoExportBillItem.ShortCode;
                else return string.Empty;
            }
        }

        public CompanyProductMark Product
        {
            get
            {
                if (maptoExportBillItem != null) return maptoExportBillItem.Product;
                else return null;
            }
        }

        public float DValuePrice
        {
            get
            {
                if (maptoExportBillItem != null) return price - maptoExportBillItem.Price;
                else return 0f;
            }
        }

        public int DValueUnitCount
        {
            get
            {
                if (maptoExportBillItem != null) return unitCount - maptoExportBillItem.UnitCount;
                else return 0;
            }
        }

        public int DValuePackageCount
        {
            get
            {
                if (maptoExportBillItem != null) return packageCount - maptoExportBillItem.PackageCount;
                else return 0;
            }
        }

        public int DValueTotalCount
        {
            get
            {
                if (maptoExportBillItem != null) return totalCount - maptoExportBillItem.TotalCount;
                else return 0;
            }
        }

        [Property]
        public float Price
        {
            get { return price; }
            set { price = value; }
        }

        [Property]
        public int UnitCount
        {
            get { return unitCount; }
            set { unitCount = value; }
        }

        [Property]
        public int PackageCount
        {
            get { return packageCount; }
            set { packageCount = value; }
        }

        [Property]
        public int TotalCount
        {
            get { return totalCount; }
            set { totalCount = value; }
        }
    }
}